#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<stdlib.h>
#include<unistd.h>
int main()
{
    //下面实现的是从文件中作为输入到buffer数组里，做一个输入重定向。
    umask(0);
    int fd = open("log.txt",O_RDONLY,0666);
    dup2(fd,0);
    char buffer[1024];
    char* c = fgets(buffer,sizeof(buffer),stdin);
    printf("buffer: %s\n",buffer);
    //umask(0);
    //int fd = open("log.txt",O_WRONLY|O_CREAT,O_TRUNC,0666);
    //dup2(fd,1);
    //printf("hello log.txt\n");




    //umask(0);
    //int fd1 = open("log1.txt",O_WRONLY|O_CREAT,O_TRUNC,0666);
    //int fd2 = open("log2.txt",O_WRONLY|O_CREAT,O_TRUNC,0666);
    //int fd3 = open("log3.txt",O_WRONLY|O_CREAT,O_TRUNC,0666);
    //int fd4 = open("log4.txt",O_WRONLY|O_CREAT,O_TRUNC,0666);
    //int fd5 = open("log5.txt",O_WRONLY|O_CREAT,O_TRUNC,0666);
   
   //// if(fd1 == -1)
   //// {
   ////     perror("open");
   ////     exit(1);
   //// }
    //printf("fd1:%d\n",fd1);
    //printf("fd2:%d\n",fd2);
    //printf("fd3:%d\n",fd3);
    //printf("fd4:%d\n",fd4);
    //printf("fd5:%d\n",fd5);
    //return 0;
}
